package org.chengn.level_middle.context2789;

/**
 * @author GengMY
 * @date 2024/3/14
 * @Description 合并后数组中的最大元素
 */
public class Context2789 {
    public long maxArrayValue(int[] nums) {
        int len = nums.length - 1;
        long res = 0L;
        long nowRes = 0L;
        for (int i = len; i >= 0; --i) {
            if (nums[i] > nowRes) {
                res = Math.max(res, nowRes);
                nowRes = 0L;
            }
            nowRes = nowRes + (long)nums[i];
            res = Math.max(res, nowRes);
        }
        return res;
    }
}
